package org.jeecg.modules.third.kaiyunshukedaikai;

import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.PropertyNamingStrategy;
import org.apache.http.HttpEntity;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.entity.mime.content.StringBody;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;

public class VehicleTest {

    /**
     * 编辑车辆信息接口测试
     * @param appid
     * @param appsecret
     * @throws UnsupportedEncodingException
     */
    public static void editVehicleTest(String appid, String appsecret){

        //业务数据
        Map<String, String> params = new TreeMap<>();
        params.put("vehicle_number","冀D0M276");
        params.put("carrier_mobile","15512348019");


        Long _aop_strtotime = System.currentTimeMillis() / 1000;
        //获取签名
        Map<String, String> data = TestHttpClientUtil.makeSignature(appid, appsecret,_aop_strtotime,params);
        HttpEntity reqEntity = null;
        try {
            reqEntity = new StringEntity(JSONUtil.toJsonStr(params),"utf-8");
            //String result = httpGet("https://test-openapi.ship56.net/tax/waybill/test");
            String result =
                    TestHttpClientUtil.httpPost("http://127.0.0.1:8080/openapi/car/ApiVehicle/edit?appid="+appid+
                            "&_aop_strtotime="+_aop_strtotime, reqEntity);

            System.out.println(result);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    /**
     * 新增车辆接口测试
     * @param appid
     * @param appsecret
     * @throws UnsupportedEncodingException
     */
    public static void addVehicleTest(String appid, String appsecret){

        //业务数据
        Map<String, String> params = new TreeMap<>();
        params.put("id_card_no", "610526199704072544");
        params.put("veh_id_no", "558555");
        params.put("permit_number", "11444");
        params.put("carrier_type", "2");
        params.put("issue_date", "1665387543");
        params.put("road_trans_cert_pic_url", "https://test.tyt2.wl168.net/upload/20220919/ff22b23caa334534872fb4510015351c.jpg");
        params.put("use_character", "123456");
        params.put("driving_lic_reg", "1665387543");
        params.put("vehicle_width", "");
        params.put("fuel_type", "05");
        params.put("carrier_name", "123456");
        params.put("vehicleLoad", "50330.0");
        params.put("vehicle_length", "13000");
        params.put("vehicle_plate_color", "2");
        params.put("vehicle_class_code", "H11");
        params.put("man_vehicle_pic_url", "https://test.tyt2.wl168.net/upload/20220919/53279f9135ef4465a88e1de9182e7ec9.jpg");
        params.put("sign_org", "陕西省西安市");
        params.put("road_trans_cert_number", "4455");
        params.put("vehicle_height", "");
        params.put("vehicle_laden_weight", "48800.0");
        params.put("carrier_mobile", "15091161111");
        params.put("driving_license_pic_url", "https://test.tyt2.wl168.net/upload/20220919/283032e5e48a455abadf29f24583cdc1.jpg");
        params.put("vehicle_number", "吉Q71222");

        Long _aop_strtotime = System.currentTimeMillis() / 1000;
        //获取签名
        params = TestHttpClientUtil.makeSignature(appid, appsecret,_aop_strtotime,params);
        HttpEntity reqEntity = null;
        try {
            reqEntity = new StringEntity(JSONUtil.toJsonStr(params),"utf-8");
            //String result = httpGet("https://test-openapi.ship56.net/tax/waybill/test");
//            String result =
//                    TestHttpClientUtil.httpPost("http://139.224.227.123:8100/openapi/car/ApiVehicle/add?appid="+appid+
//                            "&_aop_strtotime="+_aop_strtotime, reqEntity);
            String result =
                    TestHttpClientUtil.httpPost("http://localhost:8080/openapi/car/ApiVehicle/add?appid="+appid+
                            "&_aop_strtotime="+_aop_strtotime, reqEntity);

            System.out.println(result);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public static void getVehicleStatus(String appid, String appsecret){
        //业务数据
        Map<String, String> params = new TreeMap<>();
        params.put("vehicle_number","ABC56");
        Long _aop_strtotime = System.currentTimeMillis() / 1000;
        //获取签名
        Map<String, String> data = TestHttpClientUtil.makeSignature(appid, appsecret,_aop_strtotime,params);
        String _aop_signature = data.get("_aop_signature");
        HttpEntity reqEntity = null;
        try {
            reqEntity = new StringEntity(JSONUtil.toJsonStr(params));
            //String result = httpGet("https://test-openapi.ship56.net/tax/waybill/test");
            String url = "http://127.0.0.1:8080/openapi/car/ApiVehicle/getStatus?appid="+appid+
                    "&_aop_strtotime="+_aop_strtotime+"&_aop_signature="+_aop_signature;
            Map<String,Object> map = new HashMap<>();
            map.put("vehicle_number","ABC56");
            String result =
                    HttpUtil.get(url,map);

            System.out.println(result);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

    }

    public static void retrieve(String appid, String appsecret){
        //业务数据
        Map<String, String> params = new TreeMap<>();
        params.put("vehicle_number","ABC56");
        Long _aop_strtotime = System.currentTimeMillis() / 1000;
        //获取签名
        Map<String, String> data = TestHttpClientUtil.makeSignature(appid, appsecret,_aop_strtotime,params);
        String _aop_signature = data.get("_aop_signature");
        HttpEntity reqEntity = null;
        try {
            reqEntity = new StringEntity(JSONUtil.toJsonStr(params));
            //String result = httpGet("https://test-openapi.ship56.net/tax/waybill/test");
            String url = "http://127.0.0.1:8080/openapi/car/ApiVehicle/retrieve?appid="+appid+
                    "&_aop_strtotime="+_aop_strtotime+"&_aop_signature="+_aop_signature;
            Map<String,Object> map = new HashMap<>();
            map.put("vehicle_number","ABC56");
            String result =
                    HttpUtil.get(url,map);

            System.out.println(result);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

    }
}
